/**
 * File: index.tsx
 * Project: reactssr
 * Created Date: Wednesday 2018/01/03 11:52:01
 * Author: zhengjiang
 * -----
 * Last Modified: Thursday 2018/01/04 13:46:37
 * Modified By: zhengjiang
 * -----
 * Description: index route
 * 
 */

import * as React from 'react';
import { connect } from 'react-redux';
import { IIndexState } from '../store/IndexStore/reducer';
import { IStoreProps } from '../store/index';
import { Button } from 'antd';
import { indexActions } from '../store/IndexStore/action';

interface IIndexProps extends IStoreProps {
	index: IIndexState;
}

class IndexRoute extends React.PureComponent<IIndexProps, any> {
	constructor(props) {
		super(props);
	}

	setCount1 = () => {
		const { count = 0 } = this.props.index;
		this.props.dispatch(indexActions.initCount({count:count+1}));
	};
	setCount2 = () => {
		const { count = 0 } = this.props.index;
		this.props.dispatch(indexActions.initCount({count:count-1}));
	};

	render() {
        const { count = 0 } = this.props.index;
		return (
			<div>
				<div>Hello, World!</div>
				<Button onClick={this.setCount2}>-</Button>
				<span>{count}</span>
				<Button onClick={this.setCount1} type="primary">+</Button>
			</div>
		);
	}
}

export default connect(({ index }) => ({ index }))(IndexRoute);
